package org.example.commonapi.dto.onlineCode;

import lombok.Data;
import org.example.commonapi.domain.onlineCode.CommitStatistics;

import java.util.ArrayList;
import java.util.List;

@Data
public class CommitStatisticsDTO {
    private String id;
    /**
     * 问题id
     */
    private String problemId;
    /**
     * 用户名
     */
    private String username;
    /**
     * 提交类型（0：time 1：runTime 2：memory）
     */
    private Integer type;
    /**
     * 提交值
     */
    private String key;
    /**
     * 占用数量
     */
    private Double value;


    public CommitStatisticsDTO(CommitStatistics commitStatistics) {
        this.id = commitStatistics.getId();
        this.problemId = commitStatistics.getProblemId();
        this.username = commitStatistics.getUsername();
        this.type = commitStatistics.getType();
        this.key = commitStatistics.getKey();
        this.value = commitStatistics.getValue().doubleValue();
    }

    public static List<CommitStatisticsDTO> toList(List<CommitStatistics> byProblemId) {
        List<CommitStatisticsDTO> list = new ArrayList<>();
        for (CommitStatistics commitStatistics : byProblemId) {
            list.add(new CommitStatisticsDTO(commitStatistics));
        }
        return list;
    }
}
